package com.Service.Impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.Dao.BaseDaoI;
import com.Entity.Favouritevideo;
import com.Service.FavouriteVideoService;

@Service("favouritevideoservice")
public class FavouriteVideoServiceImpl extends BaseServiceImpl<Favouritevideo> implements FavouriteVideoService {
	@Autowired
	private BaseDaoI<Favouritevideo> favouritevideodao;
	List<Favouritevideo> favouritevideolist=new ArrayList<Favouritevideo>();

	@Override
	public List<Favouritevideo> findFavouriteVideoByUserId(int userId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userId", userId);
		
		String hql = "from Favouritevideo t where t.userId = :userId";
		try {
			favouritevideolist=this.favouritevideodao.find(hql, params);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return favouritevideolist;
	}
	
	@Override
	public List<Favouritevideo> findCollectedVideo (int videoId,int userId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("userId", userId);
		params.put("videoId", videoId);
		
		String hql = "from Favouritevideo t where t.videoId = :videoId and t.userId = :userId";
		try {
			favouritevideolist=this.favouritevideodao.find(hql, params);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return favouritevideolist;
	}
	
	@Override
	public Long countFavouriteNumberByVideoId(int videoId) {
		Map<String, Object> params = new HashMap<String, Object>();
		params.put("videoId", videoId);
		String hql="select count(*) from Favouritevideo t where t.videoId=:videoId";
		return favouritevideodao.count(hql, params);
	}
}
